/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.senai.view;

import br.com.senai.config.Config;
import br.com.senai.dao.AlunoDAO;
import br.com.senai.dao.CursoDAO;
import br.com.senai.dao.EscolaDAO;
import br.com.senai.dao.Escola_e_TurnoDAO;
import br.com.senai.dao.TipoDAO;
import br.com.senai.dao.TurmaDAO;
import br.com.senai.dao.TurnoDAO;
import br.com.senai.dao.UsuarioDAO;
import br.com.senai.entities.Aluno;
import br.com.senai.entities.Curso;
import br.com.senai.entities.Escola;
import br.com.senai.entities.Escola_e_Turno;
import br.com.senai.entities.Tipo;
import br.com.senai.entities.Turma;
import br.com.senai.entities.Turno;
import br.com.senai.entities.Usuario;
import java.awt.CardLayout;
import java.awt.event.KeyEvent;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import org.hibernate.HibernateException;

/**
 *
 * @author Hugo
 */
public class MenuAdm extends javax.swing.JFrame {

    /**
     * Creates new form MenuAdm
     */
    public MenuAdm() {
        initComponents();
        super.setTitle(Config.NOME_SISTEMA);
        this.setIconImage(Config.LOGO_SISTEMA);
        this.getContentPane().setBackground(Config.corFundo);
        fillcbEscola();
        fillListaEscola();
        fillcbTurma();
        fillTTurmas();
        fillTTurnos();
        fillTTipos();
        fillTAlunos();
        fillTCursos();
        fillCbTurno();
        fillcbTipo();
        atualizarCursos();
        atualizarTipos();
        atualizarAlunos();

        fillcbCurso();

    }

    public void fillcbEscola() {

        cbEscolaCurso.removeAllItems();

        cbCurso.addItem(new Object() {

            @Override
            public String toString() {
                return "Selecione...";
            }

        });

        for (Escola escola1 : new EscolaDAO().listar()) {

            cbEscolaCurso.addItem(escola1);
        }

    }

    public void fillcbCurso() {
        cbCurso.removeAllItems();

        cbCurso.addItem(new Object() {

            @Override
            public String toString() {
                return "Selecione...";
            }

        });

        for (Curso curso : new CursoDAO().listar()) {
            cbCurso.addItem(curso);
        }

    }

    public void atualizarTipos() {
        cbTipo.removeAllItems();

        DefaultTableModel tableModel = (DefaultTableModel) tTipos.getModel();

        tableModel.setNumRows(0);

        for (Tipo tipo : new TipoDAO().listar()) {
            cbTipo.addItem(tipo);

            tableModel.addRow(new Object[]{tipo, tipo.getNome()});

        }

    }

    public void fillListaEscola() {

        DefaultTableModel tableModel = (DefaultTableModel) tEscolas.getModel();

        tableModel.setNumRows(0);

        for (Escola escola : new EscolaDAO().listar()) {
            tableModel.addRow(new Object[]{escola, escola.getNome()});

        }

    }

    public static void fillcbTurma() {

        cbTurma.removeAllItems();
        cbTurma.addItem(new Object() {

            @Override
            public String toString() {
                return "Selecione...";
            }
        });

        for (Turma turma1 : new TurmaDAO().listar()) {
            cbTurma.addItem(turma1);
        }

    }
    
    public void fillcbTipo() {

        cbTipo.removeAllItems();
        cbTipo.addItem(new Object() {

            @Override
            public String toString() {
                return "Selecione...";
            }
        });

        for (Tipo tipo : new TipoDAO().listar()) {
            cbTipo.addItem(tipo);
        }

    }
    

    public void atualizarCursos() {

        DefaultTableModel tableModel = (DefaultTableModel) tCursos.getModel();

        tableModel.setNumRows(0);

        for (Curso curso : new CursoDAO().listar()) {
            tableModel.addRow(new Object[]{curso, curso.getNome(), curso.getTipo().getNome(), curso.getEscola().getNome()});

        }

    }

    public static void fillTTurmas() {

        DefaultTableModel tableModel = (DefaultTableModel) tTurmas.getModel();

        tableModel.setNumRows(0);

        for (Turma turma1 : new TurmaDAO().listar()) {
            tableModel.addRow(new Object[]{turma1, turma1.getTurno().getTurno(), turma1.getNome(), turma1.getCurso().getEscola()});

        }

    }
    
    public  void fillTCursos() {

        DefaultTableModel tableModel = (DefaultTableModel) tCursos.getModel();

        tableModel.setNumRows(0);

        for (Curso curso : new CursoDAO().listar()) {
            tableModel.addRow(new Object[]{curso, curso.getNome(), curso.getTipo(), curso.getEscola()});

        }
    }
    
    public  void fillTAlunos() {

        DefaultTableModel tableModel = (DefaultTableModel) tAlunosCadastrados.getModel();

        tableModel.setNumRows(0);

        for (Aluno aluno : new AlunoDAO().listar()) {
            tableModel.addRow(new Object[]{aluno, aluno.getRegistroAluno(), aluno.getTurma()});

        }
    }

    public void fillTTurnos() {
        DefaultTableModel tableModel = (DefaultTableModel) tTurnos.getModel();

        tableModel.setNumRows(0);

        for (Turno turno : new TurnoDAO().listar()) {

            tableModel.addRow(new Object[]{turno, turno.getTurno()});

        }

    }
    
    public void fillTTipos() {
        DefaultTableModel tableModel = (DefaultTableModel) tTipos.getModel();

        tableModel.setNumRows(0);

        for (Tipo tipo : new TipoDAO().listar()) {

            tableModel.addRow(new Object[]{tipo, tipo.getNome()});

        }

    }

    public void atualizarAlunos() {

        DefaultTableModel tableModel = (DefaultTableModel) tAlunosCadastrados.getModel();

        tableModel.setNumRows(0);

        tfRaALuno.setText(null);
        tfRaALuno.requestFocus();

        for (Aluno aluno : new AlunoDAO().listar()) {
            tableModel.addRow(new Object[]{aluno, aluno.getRegistroAluno(), aluno.getTurma().getNome()});

        }

    }

    public void fillCbTurno() {
        cbTurno.removeAllItems();
        cbTurno1.removeAllItems();

        for (Turno turno : new TurnoDAO().listar()) {

            cbTurno.addItem(turno);
            cbTurno1.addItem(turno);
        }

    }

    public void fillTHorariosEscola(Escola escola) {
        DefaultTableModel tableModel = (DefaultTableModel) tHorariosEscola.getModel();

        tableModel.setNumRows(0);

        for (Escola_e_Turno escola_e_turno : new Escola_e_TurnoDAO().listarHorariosDaEscola(escola)) {
            tableModel.addRow(new Object[]{escola_e_turno, escola_e_turno.getInicioIntervalo(), escola_e_turno.getTerminoIntervalo(), escola_e_turno.getTurno()});

        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        teste = new javax.swing.JDialog();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        root = new javax.swing.JPanel();
        turno = new javax.swing.JPanel();
        jLabel15 = new javax.swing.JLabel();
        tfTurno = new javax.swing.JTextField();
        jButton16 = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        tTurnos = new javax.swing.JTable();
        jButton17 = new javax.swing.JButton();
        jButton18 = new javax.swing.JButton();
        jLabel28 = new javax.swing.JLabel();
        escola = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        tfNomeEscola = new javax.swing.JTextField();
        jButton5 = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();
        jButton9 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        cbTurno = new javax.swing.JComboBox();
        jButton19 = new javax.swing.JButton();
        jLabel16 = new javax.swing.JLabel();
        jButton20 = new javax.swing.JButton();
        jLabel17 = new javax.swing.JLabel();
        jButton21 = new javax.swing.JButton();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        tHorariosEscola = new javax.swing.JTable();
        jScrollPane8 = new javax.swing.JScrollPane();
        tEscolas = new javax.swing.JTable();
        tfHoraInicio = new javax.swing.JFormattedTextField();
        tfHoraTermino = new javax.swing.JFormattedTextField();
        curso = new javax.swing.JPanel();
        jButton24 = new javax.swing.JButton();
        jLabel23 = new javax.swing.JLabel();
        jButton25 = new javax.swing.JButton();
        cbEscolaCurso = new javax.swing.JComboBox();
        jScrollPane7 = new javax.swing.JScrollPane();
        tCursos = new javax.swing.JTable();
        jButton22 = new javax.swing.JButton();
        cbTipo = new javax.swing.JComboBox();
        jButton26 = new javax.swing.JButton();
        jLabel24 = new javax.swing.JLabel();
        jButton27 = new javax.swing.JButton();
        tfTipoCurso = new javax.swing.JTextField();
        jLabel30 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jScrollPane6 = new javax.swing.JScrollPane();
        tTipos = new javax.swing.JTable();
        jLabel21 = new javax.swing.JLabel();
        tfNomeCurso = new javax.swing.JTextField();
        jButton23 = new javax.swing.JButton();
        jLabel22 = new javax.swing.JLabel();
        turma = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        tfNomeTurma = new javax.swing.JTextField();
        jButton6 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        cbCurso = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tTurmas = new javax.swing.JTable();
        jButton11 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jLabel27 = new javax.swing.JLabel();
        cbTurno1 = new javax.swing.JComboBox();
        aluno = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        tfRaALuno = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        cbTurma = new javax.swing.JComboBox();
        tAlunos = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        tAlunosCadastrados = new javax.swing.JTable();
        jButton28 = new javax.swing.JButton();
        jButton29 = new javax.swing.JButton();
        usuario = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        tfLogin = new javax.swing.JTextField();
        tfNomeAdm = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        tfEmail = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        tfSenha = new javax.swing.JPasswordField();
        jLabel11 = new javax.swing.JLabel();
        tfSenha1 = new javax.swing.JPasswordField();
        cbAdm = new javax.swing.JCheckBox();
        jButton7 = new javax.swing.JButton();
        jButton13 = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        jButton30 = new javax.swing.JButton();

        javax.swing.GroupLayout testeLayout = new javax.swing.GroupLayout(teste.getContentPane());
        teste.getContentPane().setLayout(testeLayout);
        testeLayout.setHorizontalGroup(
            testeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        testeLayout.setVerticalGroup(
            testeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Sistema de Pães - Menu do administrador");

        jButton1.setText("Gerenciar escolas");
        jButton1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Gerenciar turmas");
        jButton2.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Cadastrar aluno");
        jButton3.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Cadastrar usuário");
        jButton4.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        root.setLayout(new java.awt.CardLayout());

        jLabel15.setText("Turno:");

        jButton16.setText("Salvar");
        jButton16.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton16.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton16ActionPerformed(evt);
            }
        });

        tTurnos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "ID", "Turno"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane3.setViewportView(tTurnos);
        if (tTurnos.getColumnModel().getColumnCount() > 0) {
            tTurnos.getColumnModel().getColumn(0).setMinWidth(0);
            tTurnos.getColumnModel().getColumn(0).setPreferredWidth(0);
            tTurnos.getColumnModel().getColumn(0).setMaxWidth(0);
        }

        jButton17.setText("Alterar");
        jButton17.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton17.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton17ActionPerformed(evt);
            }
        });

        jButton18.setText("Remover");
        jButton18.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton18.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton18ActionPerformed(evt);
            }
        });

        jLabel28.setText("Turnos cadastrados:");

        javax.swing.GroupLayout turnoLayout = new javax.swing.GroupLayout(turno);
        turno.setLayout(turnoLayout);
        turnoLayout.setHorizontalGroup(
            turnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(turnoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(turnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3)
                    .addComponent(tfTurno)
                    .addComponent(jButton16, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(turnoLayout.createSequentialGroup()
                        .addGroup(turnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel15)
                            .addComponent(jLabel28))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(turnoLayout.createSequentialGroup()
                        .addComponent(jButton17, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                        .addComponent(jButton18, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        turnoLayout.setVerticalGroup(
            turnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(turnoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel15)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tfTurno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton16)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel28)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(turnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton17)
                    .addComponent(jButton18))
                .addContainerGap(372, Short.MAX_VALUE))
        );

        root.add(turno, "turno");

        jLabel1.setText("Nome da escola:");

        jButton5.setText("Salvar");
        jButton5.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jLabel12.setText("Escolas cadastradas:");

        jButton9.setText("Alterar");
        jButton9.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jButton10.setText("Remover");
        jButton10.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        cbTurno.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jButton19.setText("Salvar");
        jButton19.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton19.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton19ActionPerformed(evt);
            }
        });

        jLabel16.setText("CADASTRAR HORÁRIOS");

        jButton20.setText("Remover");
        jButton20.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton20.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton20ActionPerformed(evt);
            }
        });

        jLabel17.setText("Início:");

        jButton21.setText("Alterar");
        jButton21.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton21.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton21ActionPerformed(evt);
            }
        });

        jLabel18.setText("Término:");

        jLabel19.setText("Turno:");

        jLabel20.setText("Horários cadastrados:");

        tHorariosEscola.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "ID", "Início", "Término", "Turno"
            }
        ));
        jScrollPane4.setViewportView(tHorariosEscola);
        if (tHorariosEscola.getColumnModel().getColumnCount() > 0) {
            tHorariosEscola.getColumnModel().getColumn(0).setMinWidth(0);
            tHorariosEscola.getColumnModel().getColumn(0).setPreferredWidth(0);
            tHorariosEscola.getColumnModel().getColumn(0).setMaxWidth(0);
        }

        tEscolas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "ID", "Escola"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tEscolas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tEscolasMouseClicked(evt);
            }
        });
        jScrollPane8.setViewportView(tEscolas);
        if (tEscolas.getColumnModel().getColumnCount() > 0) {
            tEscolas.getColumnModel().getColumn(0).setMinWidth(0);
            tEscolas.getColumnModel().getColumn(0).setPreferredWidth(0);
            tEscolas.getColumnModel().getColumn(0).setMaxWidth(0);
        }

        try {
            tfHoraInicio.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##:##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        tfHoraInicio.setText("00:00");
        tfHoraInicio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfHoraInicioActionPerformed(evt);
            }
        });

        try {
            tfHoraTermino.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##:##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        tfHoraTermino.setText("00:00");

        javax.swing.GroupLayout escolaLayout = new javax.swing.GroupLayout(escola);
        escola.setLayout(escolaLayout);
        escolaLayout.setHorizontalGroup(
            escolaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, escolaLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel16)
                .addGap(267, 267, 267))
            .addGroup(escolaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(escolaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton19, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(tfNomeEscola)
                    .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane8)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, escolaLayout.createSequentialGroup()
                        .addGroup(escolaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(escolaLayout.createSequentialGroup()
                                .addComponent(jLabel19)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(cbTurno, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                        .addGroup(escolaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(escolaLayout.createSequentialGroup()
                                .addComponent(jLabel17)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tfHoraInicio, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel18)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tfHoraTermino, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jScrollPane4)
                    .addGroup(escolaLayout.createSequentialGroup()
                        .addGroup(escolaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel12)
                            .addComponent(jLabel20))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(escolaLayout.createSequentialGroup()
                        .addComponent(jButton21, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton20, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        escolaLayout.setVerticalGroup(
            escolaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(escolaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tfNomeEscola, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(escolaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton9)
                    .addComponent(jButton10))
                .addGap(18, 18, 18)
                .addComponent(jLabel16)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(escolaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel19)
                    .addGroup(escolaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(cbTurno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel18)
                        .addComponent(tfHoraTermino, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(tfHoraInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel17)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton19)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel20)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(escolaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton21)
                    .addComponent(jButton20))
                .addContainerGap(152, Short.MAX_VALUE))
        );

        root.add(escola, "escola");

        jButton24.setText("Remover");
        jButton24.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton24.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton24ActionPerformed(evt);
            }
        });

        jLabel23.setText("Escola:");

        jButton25.setText("Salvar");
        jButton25.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton25.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton25ActionPerformed(evt);
            }
        });

        cbEscolaCurso.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbEscolaCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbEscolaCursoActionPerformed(evt);
            }
        });

        tCursos.setAutoCreateRowSorter(true);
        tCursos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "ID", "Curso", "Tipo", "Escola"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane7.setViewportView(tCursos);
        if (tCursos.getColumnModel().getColumnCount() > 0) {
            tCursos.getColumnModel().getColumn(0).setMinWidth(0);
            tCursos.getColumnModel().getColumn(0).setPreferredWidth(0);
            tCursos.getColumnModel().getColumn(0).setMaxWidth(0);
        }

        jButton22.setText("Salvar");
        jButton22.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton22.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton22ActionPerformed(evt);
            }
        });

        cbTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jButton26.setText("Alterar");
        jButton26.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton26.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton26ActionPerformed(evt);
            }
        });

        jLabel24.setText("CADASTRAR TIPOS");

        jButton27.setText("Remover");
        jButton27.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton27.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton27ActionPerformed(evt);
            }
        });

        tfTipoCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfTipoCursoActionPerformed(evt);
            }
        });

        jLabel30.setText("Nome:");

        jLabel26.setText("Tipos cadastrados:");

        jLabel25.setText("Cursos cadastrados:");

        tTipos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "ID", "Tipos"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane6.setViewportView(tTipos);
        if (tTipos.getColumnModel().getColumnCount() > 0) {
            tTipos.getColumnModel().getColumn(0).setMinWidth(0);
            tTipos.getColumnModel().getColumn(0).setPreferredWidth(0);
            tTipos.getColumnModel().getColumn(0).setMaxWidth(0);
            tTipos.getColumnModel().getColumn(1).setResizable(false);
        }

        jLabel21.setText("Nome do curso:");

        tfNomeCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfNomeCursoActionPerformed(evt);
            }
        });

        jButton23.setText("Alterar");
        jButton23.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

        jLabel22.setText("Tipo:");

        javax.swing.GroupLayout cursoLayout = new javax.swing.GroupLayout(curso);
        curso.setLayout(cursoLayout);
        cursoLayout.setHorizontalGroup(
            cursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, cursoLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel24)
                .addGap(275, 275, 275))
            .addGroup(cursoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(cursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, cursoLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(cursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel26, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel25, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(282, 282, 282))
                    .addGroup(cursoLayout.createSequentialGroup()
                        .addGroup(cursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tfNomeCurso)
                            .addGroup(cursoLayout.createSequentialGroup()
                                .addComponent(jLabel21)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(cursoLayout.createSequentialGroup()
                                .addComponent(jButton26, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                                .addComponent(jButton27, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())
                    .addGroup(cursoLayout.createSequentialGroup()
                        .addGroup(cursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel22)
                            .addComponent(jLabel23)
                            .addComponent(cbTipo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, cursoLayout.createSequentialGroup()
                        .addGroup(cursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton22, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cbEscolaCurso, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, cursoLayout.createSequentialGroup()
                        .addComponent(jScrollPane6)
                        .addContainerGap())
                    .addGroup(cursoLayout.createSequentialGroup()
                        .addComponent(jScrollPane7)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, cursoLayout.createSequentialGroup()
                        .addComponent(jButton25, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(cursoLayout.createSequentialGroup()
                        .addComponent(tfTipoCurso)
                        .addContainerGap())
                    .addGroup(cursoLayout.createSequentialGroup()
                        .addGroup(cursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(cursoLayout.createSequentialGroup()
                                .addComponent(jLabel30)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(cursoLayout.createSequentialGroup()
                                .addComponent(jButton23, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton24, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())))
        );
        cursoLayout.setVerticalGroup(
            cursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(cursoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel21)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tfNomeCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel22)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cbTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel23)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cbEscolaCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton22)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel25)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(cursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton27)
                    .addComponent(jButton26))
                .addGap(18, 18, 18)
                .addComponent(jLabel24)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel30)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tfTipoCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton25)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel26)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(cursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton23)
                    .addComponent(jButton24))
                .addContainerGap(57, Short.MAX_VALUE))
        );

        root.add(curso, "curso");

        jLabel2.setText("Nome da turma:");

        jButton6.setText("Salvar");
        jButton6.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jLabel3.setText("Curso:");

        cbCurso.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione..." }));
        cbCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbCursoActionPerformed(evt);
            }
        });

        jLabel13.setText("Turmas cadastradas:");

        tTurmas.setAutoCreateRowSorter(true);
        tTurmas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "id", "Turno", "Turma", "Escola"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tTurmas);
        if (tTurmas.getColumnModel().getColumnCount() > 0) {
            tTurmas.getColumnModel().getColumn(0).setMinWidth(0);
            tTurmas.getColumnModel().getColumn(0).setPreferredWidth(0);
            tTurmas.getColumnModel().getColumn(0).setMaxWidth(0);
        }

        jButton11.setText("Alterar");
        jButton11.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });

        jButton12.setText("Remover");
        jButton12.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });

        jLabel27.setText("Turno:");

        cbTurno1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout turmaLayout = new javax.swing.GroupLayout(turma);
        turma.setLayout(turmaLayout);
        turmaLayout.setHorizontalGroup(
            turmaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, turmaLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jLabel13)
                .addGap(274, 274, 274))
            .addGroup(turmaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(turmaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cbCurso, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(tfNomeTurma)
                    .addComponent(cbTurno1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 633, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, turmaLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton12, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(turmaLayout.createSequentialGroup()
                        .addGroup(turmaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel27)
                            .addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        turmaLayout.setVerticalGroup(
            turmaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(turmaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tfNomeTurma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cbCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel27)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cbTurno1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel13)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(turmaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton12)
                    .addComponent(jButton11))
                .addContainerGap(277, Short.MAX_VALUE))
        );

        root.add(turma, "turma");

        jLabel5.setText("RA:");

        tfRaALuno.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfRaALunoKeyPressed(evt);
            }
        });

        jLabel6.setText("Turma:");

        cbTurma.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        tAlunos.setText("Salvar");
        tAlunos.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        tAlunos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tAlunosActionPerformed(evt);
            }
        });

        jLabel14.setText("Alunos cadastrados:");

        tAlunosCadastrados.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Id", "RA", "Turma"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane5.setViewportView(tAlunosCadastrados);
        if (tAlunosCadastrados.getColumnModel().getColumnCount() > 0) {
            tAlunosCadastrados.getColumnModel().getColumn(0).setMinWidth(0);
            tAlunosCadastrados.getColumnModel().getColumn(0).setPreferredWidth(0);
            tAlunosCadastrados.getColumnModel().getColumn(0).setMaxWidth(0);
        }

        jButton28.setText("Alterar");
        jButton28.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

        jButton29.setText("Remover");
        jButton29.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton29.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton29ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout alunoLayout = new javax.swing.GroupLayout(aluno);
        aluno.setLayout(alunoLayout);
        alunoLayout.setHorizontalGroup(
            alunoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(alunoLayout.createSequentialGroup()
                .addGroup(alunoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(alunoLayout.createSequentialGroup()
                        .addGroup(alunoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(alunoLayout.createSequentialGroup()
                                .addGap(277, 277, 277)
                                .addComponent(jLabel14))
                            .addGroup(alunoLayout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jButton28, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(alunoLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(alunoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tfRaALuno, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(tAlunos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(alunoLayout.createSequentialGroup()
                                .addGroup(alunoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel5))
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(cbTurma, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 633, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, alunoLayout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jButton29, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );
        alunoLayout.setVerticalGroup(
            alunoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(alunoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tfRaALuno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cbTurma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tAlunos)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(alunoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton28)
                    .addComponent(jButton29))
                .addContainerGap(310, Short.MAX_VALUE))
        );

        root.add(aluno, "aluno");

        jLabel7.setText("Login:");

        jLabel8.setText("Nome:");

        jLabel9.setText("Email:");

        jLabel10.setText("Senha:");

        jLabel11.setText("Confirmar senha:");

        cbAdm.setText("Administrador");
        cbAdm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbAdmActionPerformed(evt);
            }
        });

        jButton7.setText("Salvar");
        jButton7.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton13.setText("Exibir usuários cadastros");
        jButton13.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

        javax.swing.GroupLayout usuarioLayout = new javax.swing.GroupLayout(usuario);
        usuario.setLayout(usuarioLayout);
        usuarioLayout.setHorizontalGroup(
            usuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(usuarioLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(usuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(usuarioLayout.createSequentialGroup()
                        .addGroup(usuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9)
                            .addComponent(jLabel7)
                            .addComponent(jLabel10)
                            .addComponent(jLabel11)
                            .addComponent(cbAdm))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jButton7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(tfSenha1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(tfSenha, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(tfLogin, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(tfNomeAdm, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(tfEmail)
                    .addComponent(jButton13, javax.swing.GroupLayout.DEFAULT_SIZE, 633, Short.MAX_VALUE))
                .addContainerGap())
        );
        usuarioLayout.setVerticalGroup(
            usuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(usuarioLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tfNomeAdm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tfEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tfLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tfSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tfSenha1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cbAdm)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton7)
                .addGap(18, 18, 18)
                .addComponent(jButton13)
                .addContainerGap(273, Short.MAX_VALUE))
        );

        root.add(usuario, "usuario");

        jButton14.setText("Gerenciar turnos");
        jButton14.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });

        jButton30.setText("Gerenciar cursos");
        jButton30.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton30.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton30ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton30, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(root, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(root, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(105, 105, 105)
                .addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton30, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(7, 7, 7)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton1, jButton2, jButton3, jButton4});

        setSize(new java.awt.Dimension(816, 637));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void cbAdmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbAdmActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbAdmActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        if (!tfNomeAdm.getText().isEmpty() && !tfEmail.getText().isEmpty() && !tfLogin.getText().isEmpty() && tfSenha.getPassword().length != 0 && tfSenha1.getPassword().length != 0) {
            if (tfEmail.getText().matches("[a-z0-9]{4,}@[a-z]+(.com|.com.[a-z]+)")) {
                if (Arrays.equals(tfSenha.getPassword(), tfSenha1.getPassword())) {
                    Usuario u = new Usuario();
                    u.setLogin(tfLogin.getText());
                    u.setNome(tfNomeAdm.getText());
                    u.setEmail(tfEmail.getText());

                    u.setSenha(Config.criptograrSenha(tfSenha.getPassword()));
                    u.setAdministrador(cbAdm.isSelected());

                    new UsuarioDAO().salvar(u);
                    JOptionPane.showMessageDialog(null, "Salvo com sucesso.");

                } else {
                    JOptionPane.showMessageDialog(null, "Senhas não coincidem.", "Resposta", JOptionPane.INFORMATION_MESSAGE);

                }

            } else {
                JOptionPane.showMessageDialog(null, "Email incorreto.", "Resposta", JOptionPane.INFORMATION_MESSAGE);

            }
        } else {
            JOptionPane.showMessageDialog(null, "Preencha os campos corretamente.", "Resposta", JOptionPane.INFORMATION_MESSAGE);

        }


    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        CardLayout c = (CardLayout) root.getLayout();
        c.show(root, "escola");
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        CardLayout c = (CardLayout) root.getLayout();
        c.show(root, "turma");
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        CardLayout c = (CardLayout) root.getLayout();
        c.show(root, "aluno");
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        CardLayout c = (CardLayout) root.getLayout();
        c.show(root, "usuario");
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        if (!tfNomeEscola.getText().isEmpty()) {
            Escola e = new Escola();

            e.setNome(tfNomeEscola.getText());

            new EscolaDAO().salvar(e);

            fillcbEscola();
            fillListaEscola();
            tfNomeEscola.setText(null);
            tfNomeEscola.requestFocus();

        } else {
            JOptionPane.showMessageDialog(null, "Insira o nome da escola no campo.", "Resposta", JOptionPane.INFORMATION_MESSAGE);
            tfNomeEscola.requestFocus();
        }


    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed

        if (!tfNomeTurma.getText().isEmpty() && !cbCurso.getSelectedItem().toString().equalsIgnoreCase("Selecione...")) {

            Turma t = new Turma();

            t.setNome(tfNomeTurma.getText());

            t.setAtiva(true);
            t.setCurso((Curso) cbCurso.getSelectedItem());
            t.setTurno((Turno) cbTurno1.getSelectedItem());

            new TurmaDAO().salvar(t);

            fillcbTurma();
            fillTTurmas();
            tfNomeTurma.setText(null);

        } else {
            JOptionPane.showMessageDialog(null, "Preencha os campos corretamente.", "Resposta", JOptionPane.INFORMATION_MESSAGE);
        }


    }//GEN-LAST:event_jButton6ActionPerformed

    private void cbCursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbCursoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbCursoActionPerformed
    public void cadastrar() {

        if (!tfRaALuno.getText().isEmpty() && !cbTurma.getSelectedItem().toString().equalsIgnoreCase("Selecione...")) {

            Aluno a = new Aluno();
            a.setRegistroAluno(Long.parseLong(tfRaALuno.getText()));
            a.setTurma((Turma) cbTurma.getSelectedItem());

            try {
                new AlunoDAO().salvar(a);

                atualizarAlunos();

                new MensagemSalvo().setVisible(true);

            } catch (HibernateException e) {
                atualizarAlunos();
                              new MensagemNaoSalvo().setVisible(true);

            }
      

        } else {

            JOptionPane.showMessageDialog(null, "Preencha os campos corretamente.", "Resposta", JOptionPane.INFORMATION_MESSAGE);
            tfRaALuno.setText(null);
            tfRaALuno.requestFocus();

        }
    }
    private void tAlunosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tAlunosActionPerformed

        cadastrar();

    }//GEN-LAST:event_tAlunosActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        if (tEscolas.getSelectedRowCount() > 0) {
            Escola e = (Escola) tEscolas.getValueAt(tEscolas.getSelectedRow(), 0);
            String nome = (String) JOptionPane.showInputDialog(null, "Nome da escola:", "Alterar dados ", JOptionPane.QUESTION_MESSAGE, null, null, e.getNome());

            try {
                if (!nome.isEmpty()) {

                    e.setNome(nome);
                    new EscolaDAO().atualizar(e);
                    fillListaEscola();
                    fillcbEscola();

                } else {
                    JOptionPane.showMessageDialog(null, "Insira o nome da escola", "Aviso", JOptionPane.INFORMATION_MESSAGE);
                }

            } catch (NullPointerException ex) {

            }

        }

    }//GEN-LAST:event_jButton9ActionPerformed

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed

        if (tEscolas.getSelectedRowCount() > 0) {
            Escola e = (Escola) tEscolas.getValueAt(tEscolas.getSelectedRow(), 0);
            if (JOptionPane.showConfirmDialog(null, "Deseja excluir essa escola?\nNome:" + e.getNome() + "\n*Não será possível reverter o processo", "Confirmar exclusão", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                new EscolaDAO().deletar(e);
                fillListaEscola();
            }
        }

    }//GEN-LAST:event_jButton10ActionPerformed
    public static int idTurma;
    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed

        if (tTurmas.getSelectedRowCount() > 0) {
            idTurma = (int) tTurmas.getValueAt(tTurmas.getSelectedRow(), 0);
            new EditarTurma().setVisible(true);

        }
    }//GEN-LAST:event_jButton11ActionPerformed

    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
        if (tTurmas.getSelectedRowCount() > 0) {
            Turma t = (Turma) tTurmas.getValueAt(tTurmas.getSelectedRow(), 0);
            if (JOptionPane.showConfirmDialog(null, "Deseja excluir essa turma?\nNome:" + t.getNome() + "\nEscola:" + t.getCurso().getEscola() + "\n*Não será possível reverter o processo", "Confirmar exclusão", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

                new TurmaDAO().deletar(t);
                fillTTurmas();

            }
        }
    }//GEN-LAST:event_jButton12ActionPerformed

    private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
        CardLayout c = (CardLayout) root.getLayout();
        c.show(root, "turno");

    }//GEN-LAST:event_jButton14ActionPerformed

    private void tfTipoCursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfTipoCursoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfTipoCursoActionPerformed

    private void jButton19ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton19ActionPerformed
        if (tEscolas.getSelectedRowCount() > 0) {

            Escola_e_Turno escola_e_turno = new Escola_e_Turno();

            Escola e = (Escola) tEscolas.getValueAt(tEscolas.getSelectedRow(), 0);

            escola_e_turno.setEscola(e);

            escola_e_turno.setTurno((Turno) cbTurno.getSelectedItem());

            try {
                escola_e_turno.setInicioIntervalo(new SimpleDateFormat("HH:mm").parse(tfHoraInicio.getText()));
                escola_e_turno.setTerminoIntervalo(new SimpleDateFormat("HH:mm").parse(tfHoraTermino.getText()));
            } catch (ParseException ex) {
                Logger.getLogger(MenuAdm.class.getName()).log(Level.SEVERE, null, ex);

            }
            new Escola_e_TurnoDAO().salvar(escola_e_turno);

            JOptionPane.showMessageDialog(null, "Salvo.");

            fillTHorariosEscola(e);

        }


    }//GEN-LAST:event_jButton19ActionPerformed

    private void jButton20ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton20ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton20ActionPerformed

    private void jButton21ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton21ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton21ActionPerformed

    private void jButton30ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton30ActionPerformed
        CardLayout c = (CardLayout) root.getLayout();
        c.show(root, "curso");


    }//GEN-LAST:event_jButton30ActionPerformed

    private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton16ActionPerformed

        if (!tfTurno.getText().isEmpty()) {

            Turno t = new Turno();

            t.setTurno(tfTurno.getText());

            new TurnoDAO().salvar(t);

            JOptionPane.showMessageDialog(null, "Salvo.");

            fillTTurnos();
            fillCbTurno();

            tfTurno.setText(null);

            tfTurno.requestFocus();

        } else {
            JOptionPane.showMessageDialog(null, "Preencha os campos!");
        }


    }//GEN-LAST:event_jButton16ActionPerformed

    private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton18ActionPerformed
        if (tTurnos.getSelectedRowCount() > 0) {

            Turno t = (Turno) tTurnos.getValueAt(tTurnos.getSelectedRow(), 0);

            new TurnoDAO().deletar(t);

            fillTTurnos();
            fillCbTurno();

        }


    }//GEN-LAST:event_jButton18ActionPerformed

    private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton17ActionPerformed
        if (tTurnos.getSelectedRowCount() > 0) {

            Turno t = (Turno) tTurnos.getValueAt(tTurnos.getSelectedRow(), 0);

            String nome = (String) JOptionPane.showInputDialog(null, "Turno:", "Alterar dados ", JOptionPane.QUESTION_MESSAGE, null, null, t.getTurno());

            try {
                if (!nome.isEmpty()) {

                    t.setTurno(nome);

                    new TurnoDAO().atualizar(t);

                    fillTTurnos();
                    fillCbTurno();
                    JOptionPane.showMessageDialog(null, "Atualizado");

                } else {
                    JOptionPane.showMessageDialog(null, "Insira o nome do turno");

                }
            } catch (NullPointerException ex) {

            }

        }
    }//GEN-LAST:event_jButton17ActionPerformed

    private void tEscolasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tEscolasMouseClicked
        if (tEscolas.getSelectedRowCount() > 0) {

            Escola e = (Escola) tEscolas.getValueAt(tEscolas.getSelectedRow(), 0);

            fillTHorariosEscola(e);

        }


    }//GEN-LAST:event_tEscolasMouseClicked

    private void cbEscolaCursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbEscolaCursoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbEscolaCursoActionPerformed

    private void jButton26ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton26ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton26ActionPerformed

    private void jButton25ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton25ActionPerformed

        if (!tfTipoCurso.getText().isEmpty()) {

            Tipo t = new Tipo();

            t.setNome(tfTipoCurso.getText());

            new TipoDAO().salvar(t);

            JOptionPane.showMessageDialog(null, "salvo.");

            atualizarTipos();
            tfTipoCurso.setText("");

        } else {
            JOptionPane.showMessageDialog(null, "Preecha o campo.");
        }


    }//GEN-LAST:event_jButton25ActionPerformed

    private void jButton22ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton22ActionPerformed
        if (!tfNomeCurso.getText().isEmpty()) {

            Curso c = new Curso();

            c.setEscola((Escola) cbEscolaCurso.getSelectedItem());
            c.setTipo((Tipo) cbTipo.getSelectedItem());
            c.setNome(tfNomeCurso.getText());

            new CursoDAO().salvar(c);

            new Config().mensagemSalvo();

            atualizarCursos();
            
            tfNomeCurso.setText("");

        }
    }//GEN-LAST:event_jButton22ActionPerformed

    private void tfRaALunoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfRaALunoKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            cadastrar();
        }

    }//GEN-LAST:event_tfRaALunoKeyPressed

    private void tfHoraInicioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfHoraInicioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfHoraInicioActionPerformed

    private void jButton24ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton24ActionPerformed
        if (tTipos.getSelectedRowCount() > 0) {

            Tipo t = (Tipo) tTipos.getValueAt(tTipos.getSelectedRow(), 0);

            new TipoDAO().deletar(t);

            fillTTipos();
            fillcbTipo();

        }
    }//GEN-LAST:event_jButton24ActionPerformed

    private void jButton27ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton27ActionPerformed
         if (tCursos.getSelectedRowCount() > 0) {
            Curso c = (Curso) tCursos.getValueAt(tCursos.getSelectedRow(), 0);
            if (JOptionPane.showConfirmDialog(null, "Deseja excluir esse curso?\nNome:" + c.getNome() + "\n*Não será possível reverter o processo", "Confirmar exclusão", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                new CursoDAO().deletar(c);
                fillTCursos();
            }
        }
    }//GEN-LAST:event_jButton27ActionPerformed

    private void tfNomeCursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfNomeCursoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfNomeCursoActionPerformed

    private void jButton29ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton29ActionPerformed
         if (tAlunosCadastrados.getSelectedRowCount() > 0) {
            Aluno a = (Aluno) tAlunosCadastrados.getValueAt(tAlunosCadastrados.getSelectedRow(), 0);
            if (JOptionPane.showConfirmDialog(null, "Deseja excluir esse aluno?\nRA:" + a.getRegistroAluno() + "\nTurma:" + a.getTurma()+"\n*Não será possível reverter o processo", "Confirmar exclusão", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                new AlunoDAO().deletar(a);
                fillTAlunos();
            }
        }
    }//GEN-LAST:event_jButton29ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MenuAdm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MenuAdm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MenuAdm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MenuAdm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MenuAdm().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel aluno;
    private javax.swing.JCheckBox cbAdm;
    private javax.swing.JComboBox cbCurso;
    private javax.swing.JComboBox cbEscolaCurso;
    private javax.swing.JComboBox cbTipo;
    private static javax.swing.JComboBox cbTurma;
    private javax.swing.JComboBox cbTurno;
    private javax.swing.JComboBox cbTurno1;
    private javax.swing.JPanel curso;
    private javax.swing.JPanel escola;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton16;
    private javax.swing.JButton jButton17;
    private javax.swing.JButton jButton18;
    private javax.swing.JButton jButton19;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton20;
    private javax.swing.JButton jButton21;
    private javax.swing.JButton jButton22;
    private javax.swing.JButton jButton23;
    private javax.swing.JButton jButton24;
    private javax.swing.JButton jButton25;
    private javax.swing.JButton jButton26;
    private javax.swing.JButton jButton27;
    private javax.swing.JButton jButton28;
    private javax.swing.JButton jButton29;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton30;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JPanel root;
    private javax.swing.JButton tAlunos;
    private javax.swing.JTable tAlunosCadastrados;
    private javax.swing.JTable tCursos;
    private javax.swing.JTable tEscolas;
    private javax.swing.JTable tHorariosEscola;
    private javax.swing.JTable tTipos;
    private static javax.swing.JTable tTurmas;
    private javax.swing.JTable tTurnos;
    private javax.swing.JDialog teste;
    private javax.swing.JTextField tfEmail;
    private javax.swing.JFormattedTextField tfHoraInicio;
    private javax.swing.JFormattedTextField tfHoraTermino;
    private javax.swing.JTextField tfLogin;
    private javax.swing.JTextField tfNomeAdm;
    private javax.swing.JTextField tfNomeCurso;
    private javax.swing.JTextField tfNomeEscola;
    private javax.swing.JTextField tfNomeTurma;
    private javax.swing.JTextField tfRaALuno;
    private javax.swing.JPasswordField tfSenha;
    private javax.swing.JPasswordField tfSenha1;
    private javax.swing.JTextField tfTipoCurso;
    private javax.swing.JTextField tfTurno;
    private javax.swing.JPanel turma;
    private javax.swing.JPanel turno;
    private javax.swing.JPanel usuario;
    // End of variables declaration//GEN-END:variables
}
